package com.jch.dm5_producer_consumer.reusable_code;

import java.util.concurrent.BlockingQueue;

// 生产者-消费者模式：Channel接口实现类
public class BlockingQueueChannel<P> implements Channel<P> {

    private final BlockingQueue<P> blockingQueue;

    public BlockingQueueChannel(BlockingQueue<P> queue){
        blockingQueue = queue;
    }

    @Override
    public void put(P p) throws InterruptedException {
        blockingQueue.put(p);
    }

    @Override
    public P take() throws InterruptedException {
        return blockingQueue.take();
    }
}
